package com.myexam.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.RequestAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.myexam.model.Subject;
import com.myexam.service.SubjectService;
import com.myexam.util.Page;
import com.myexam.util.PageResult;
import com.myexam.util.PageUtil;
import com.opensymphony.xwork2.ActionSupport;
@Controller
@Scope("prototype")
public class SubjectQueryAction extends ActionSupport implements RequestAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = 566134530581384683L;
	private Map<String, Object> request;
	@Autowired
	private SubjectService subjectService;
	private int currentPage;
	
	
	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public Map<String, Object> getRequest() {
		return request;
	}

	public void setRequest(Map<String, Object> request) {
		this.request = request;
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public String execute() throws Exception{
		Page page = PageUtil.getPage(5,currentPage);
		PageResult pageResult = subjectService.querySubjectByPage(page);
		List<Subject> subjects = pageResult.getList();
		page = pageResult.getPage();
		request.put("page", page);
		request.put("subjects", subjects);
		return SUCCESS;
	}
	
}
